package Client;

import Client.proxy.ClientProxy;
import common.pojo.User;
import common.service.UserService;

public class TestClient {
    public static void main(String[] args) throws InterruptedException {
        // 创建代理对象
        //ClientProxy clientProxy = new ClientProxy("127.0.0.1", 8899);
        ClientProxy clientProxy = new ClientProxy();
        // 获取UserService的代理对象
        UserService userServiceProxy = clientProxy.getProxy(UserService.class);
        for (int i = 0; i < 120; i++){
            Integer i1 = i;
            if (i1 % 30 == 0){
                Thread.sleep(1000);
            }
            new Thread(() -> {
                try {
                    User user = userServiceProxy.getUserById(i1);
                    System.out.println("服务端返回的user=" + user.toString());
                    Integer id = userServiceProxy.insertUserId(User.builder()
                            .userName("小红"+ i1.toString())
                            .id(i1)
                            .sex(false).build());
                } catch (Exception e) {
                    System.out.println("异常=" + e.getMessage());
                }
            }).start();
        }
//        User user = userServiceProxy.getUserById(1);
//        System.out.println("服务端返回的user=" + user.toString());
//
//        User newNewUser = User.builder()
//                .userName("小红")
//                .id(2)
//                .sex(false).build();
//        Integer id = userServiceProxy.insertUserId(newNewUser);
//        System.out.println("插入用户id=" + id);
//
//        User user2 = userServiceProxy.getUserById(id);
//        System.out.println("服务端返回的user2=" + user2.toString());

    }
}
